package org.onepiece.admin.common.config.advice;

import org.onepiece.admin.common.utils.CommonResult;
import org.onepiece.admin.common.constant.CommonConstants;
import org.onepiece.admin.common.exception.BusinessException;
import org.onepiece.admin.common.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zhujianke@gaodun.com
 * @since 2023/2/15 17:35
 */
@RestControllerAdvice(basePackages = {CommonConstants.COMMON_EXCEPTION_ADVICE_PACKAGE})
public class CommonExceptionAdvice {

    @ExceptionHandler(value = {BusinessException.class})
    public CommonResult<Void> handleBusinessException(BusinessException e) {
        return CommonResult.create(e.getServiceCode());
    }

    @ExceptionHandler(value = {SystemException.class})
    public CommonResult<Void> handleSystemException(SystemException e) {
        return CommonResult.create(e.getServiceCode());
    }

}
